<template>
  <div
    class="cardWrapper"
    :id="`menuScroll${scrollFirstIndex}-${componentsIndex}`"
    v-if="layerItem.children.length"
  >
    <div class="cardTitleContainer">
      <img
        src="https://img3.job1001.com/data_center/images/position_item_icon.png"
        alt="Icon"
        class="position_item_icon"
      />
      <div class="cardTitle">{{ layerItem.title }}</div>
    </div>
    <div class="layerList">
      <el-row class="demo-autocomplete" :key="index" v-for="(item, index) in layerItem.children || layerList">
        <div class="demo-autocomplete-content" :id="`scroll${componentsIndex}-${index}`">
          <div class="chanceContainer" v-loading="loading">
            <!-- 这里的模块就按照id分组进行开发 -->
            <!-- {{ item.title +''+JSON.stringify(item.layerId) }} -->
            <!-- levelPromotion这个组件有多个组合而成，包括209等级证书，206专业知识 207专业技能，208能力素质，会再嵌套一层 -->
            <levelPromotion
              v-if="item.layerId == 209"
              :thirdLayerList="layerItem.children"
            />
            <jobPersonality
              :jobPersonalityData="item"
              v-if="item.layerId == 203"
            />
            <levelSalary v-if="item.layerId == 204" />
            <jobBenchmark :jobBenchmarkData="item" v-if="item.layerId == 210" />
            <swot :swotData="item" v-if="item.layerId == 205" />
          </div>
        </div>
      </el-row>
    </div>
    <div class="pagination" style="margin-top: 10px;line-height: 30px;color: #888888;font-size: 14px;">版权声明：本平台数据基于近一年企业公开招聘信息统计分析生成，因样本选择、统计算法差异等因素可能存在偏差，仅作参考之用。数据版权归一览1001研究院所有，任何单位或个人引用须明确标注来源并附原文链接。</div>
  </div>
</template>

<script>
import { reqChartJobs } from "@/api/position-detail.js";
import levelPromotion from "./components/levelPromotion";
import levelSalary from "./components/levelSalary";
import swot from "./components/swot";
import jobPersonality from "./components/jobPersonality";
import jobBenchmark from "./components/jobBenchmark";

export default {
  name: "developmenPathSecond",
  components: {
    levelPromotion,
    levelSalary,
    swot,
    jobPersonality,
    jobBenchmark,
  },
  props: {
    layerList: {
      type: Array,
      default: () => [],
    },
    layerItem: {
      type: Object,
      default: () => {},
    },
    topId: {
      type: String,
      required: true,
    },
    isSuperToken: {
      type: Boolean,
      default: false,
    },
    scrollFirstIndex: {
      type: [String, Number],
      default: 0,
    },
    aiCreateStatus: {
      type: Boolean,
      default: false,
    },
  },
  watch: {
    layerItem: {
      handler(newValue, oldValue) {
        console.log("second layerItem", newValue);

        if (newValue.layerId) {
          this.layerList.forEach((item, index) => {
            if (item.layerId == newValue.layerId) {
              this.componentsIndex = index;
            }
          });
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      loading: false,
      form: {},
      chanceList: [],
      regionList: [],
      selectedIndustryList: [],
      selectedCompanyList: [],
      selectedTargetList: [],
      tablePage: {
        pageNum: 1, // 第几页
        pageSize: 10, // 每页多少条
        total: 0, // 总记录数
      },

      pageSizes: [10, 20, 30],
      positionId: this.$route.query.id,
      componentsIndex: "", //用来标记组件下标，滚动用
    };
  },
  methods: {
    fetchData() {
      this.loading = true;
      const params = {
        ylPositionId: this.positionId,
        pageNo: this.tablePage.pageNum,
        pageSize: this.tablePage.pageSize,
      };
      if (this.regionList != []) {
        params.regionId = this.regionList.join(",");
      }
      if (this.selectedIndustryList != []) {
        params.industryId = this.selectedIndustryList.join(",");
      }
      if (this.selectedCompanyList != []) {
        params.comScaleId = this.selectedCompanyList.join(",");
      }
      if (this.selectedTargetList != []) {
        params.isGraduate = this.selectedTargetList.join(",");
      }
      if (this.selectBetweenTime != null && this.selectBetweenTime != "") {
        params.selectBeginTime = this.selectBetweenTime[0];
        params.selectEndTime = this.selectBetweenTime[1];
      }
      reqChartJobs(params)
        .then((res) => {
          if (res.code == 200) {
            this.chanceList = res.data.map(function (v) {
              if (v.salaryUp & v.salaryDown) {
                v.salaryUp = (v.salaryUp / 1000).toFixed(1) + "k";
                v.salaryDown = (v.salaryDown / 1000).toFixed(1) + "k";
              }
              return v;
            });
            this.tablePage.total = res.pageparam.sums;
          }
        })
        .catch((e) => {
          //console.log("e");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    onRegionChange(val) {
      //console.log("onRegionChange--------->", val.label);
      this.regionList = [val.value];
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    onTargetChange(val) {
      this.selectedTargetList = [];
      if (val && val.length) {
        val.forEach((item) => {
          this.selectedTargetList.push(item.split("-")[0]);
        });
      } else {
        this.selectedTargetList = [];
      }
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    onCompanyChange(val) {
      this.selectedCompanyList = [];
      if (val && val.length) {
        val.forEach((item) => {
          this.selectedCompanyList.push(item.split("-")[0]);
        });
      } else {
        this.selectedCompanyList = [];
      }
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    onIndustryChange(val) {
      //console.log("onIndustryChange", val);
      this.selectedIndustryList = [];
      if (val && val.length) {
        val.forEach((item) => {
          this.selectedIndustryList.push(item.split("-")[0]);
        });
      } else {
        this.selectedIndustryList = [];
      }
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    handlePageChange(currentPage) {
      this.tablePage.pageNum = currentPage;
      this.fetchData();
    },
    handleSizeChange(pageSize) {
      this.tablePage.pageSize = pageSize;
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
  },
};
</script>

<style lang="scss" scoped>
.cardWrapper {
  // position: relative;
  min-width: 800px;
  border-radius: 10px;
  border: 1px solid #cbdcfe;
  background-size: 110% 219px;
  background-position: -10px -10px;
  background-image: url("https://img3.job1001.com/data_center/images/salary_bg.png");
  background-repeat: no-repeat;
  padding: 20px;
  flex: 1;
  margin-bottom: 14px;
  margin-top: 20px;
   margin-top: 0;
  &::-webkit-scrollbar {
    width: 4px;
    background-color: #fff;
    border-radius: 4px;

    height: 4px;
  }
  &::-webkit-scrollbar-thumb {
    background-color: #d8d8d8;
    border-radius: 4px;
  }
  .cardTitleContainer {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    // position: sticky;
    top: 0;
    .cardTitle {
      height: 30px;
      font-size: 22px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 600;
      color: #000000;
      line-height: 30px;
      margin-right: 15px;
    }
    .position_item_icon {
      width: 39px;
      height: 40px;
      margin-right: 13px;
    }
  }

  .layerList {
    .demo-autocomplete {
      display: flex;
      .demo-autocomplete-content {
        flex: 1;
      }
      .positionPic {
        width: 140px;
        // height: 137px;
        border-radius: 16px;
        opacity: 0.77;
      }
    }
  }
  .titleFlag {
    width: 5px;
    height: 15px;
    border-radius: 3px;
    background: #4880ff;
    margin-right: 12px;
  }
  .controlLine {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 15px;
    .tinyTitle {
      display: flex;
      align-items: center;
      font-weight: bold;
      font-size: 18px;
      // margin-right: 24px;
    }
    .line {
      flex: 1;
      // height: 16px;
      margin-left: 14px;
      border-bottom: 1px solid #efefef;
    }
  }
}

.chanceContent {
  padding-top: 10px;
  .position-item {
    display: flex;
    margin-bottom: 12px;
    padding: 24px 12px;
    border: 1px solid #f3f3f3;
    border-radius: 8px;
    box-shadow: 0 8px 18px 1px #f3f3f3;
  }
  p {
    margin-top: 0;
    margin-bottom: 0;
  }
  .divider-vertical {
    border-left: 1px #dcdfe6 solid;
    display: inline-block;
    height: 1em;
    margin: 0 8px;
    position: relative;
    vertical-align: middle;
    width: 1px;
  }
  .position {
    &-left {
      width: 400px;

      .position-title {
        padding-bottom: 12px;
        font-size: 18px;
      }
    }

    &-middle {
      width: 350px;
      .company-name {
        padding-bottom: 12px;
        font-size: 16px;
      }

      .company-address {
        padding-bottom: 5px;
        font-size: 14px;
        line-height: 2;
        min-height: 28px;
        color: #999;
      }
    }

    &-right {
      width: 100px;
      text-align: center;

      .company-logo {
        margin-bottom: 12px;
        width: 71px;
        height: 43px;
      }
    }
  }

  .welfare-item {
    display: inline-block;
    padding: 0 5px;
    margin-right: 10px;
    margin-bottom: 5px;
    line-height: 18px;
    font-size: 12px;
    color: #666;
    border: solid 1px #c9c9c9;
    border-radius: 4px;
  }

  .condition {
    padding-bottom: 5px;
    font-size: 14px;
  }
  .condition-item {
    line-height: 2;
  }

  .update-time {
    margin-top: 2px;
    font-size: 12px;
    color: #a1a1a1;
  }
  .salary {
    color: red;
  }
}
.pagination {
  display: flex;
  justify-content: center;
  position: relative;
  margin-top: 24px;
}
::v-deep .el-form-item {
  display: flex;
  align-items: center;
  margin-bottom: 0;
}
::v-deep .el-form-item__label {
  display: flex;
  align-items: center;
  justify-content: center;
  // height: 27px;
  min-width: 90px !important;
}
::v-deep .el-button--primary {
  color: #fff;
  background: #0b6eff;
  border-color: #0b6eff;
}
::v-deep .el-button--primary.is-plain {
  color: #409eff;
  background: #fff;
  border-color: #b3d8ff;
}
</style>
